home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows4 / pcproj.zip / TASK.CLS < prev    next >
Text File  |  1988-11-30  |  5KB  |  209 lines

  1. /* A Task is an activity that requires time and resources to
  2.    complete.  Tasks should only have a single input and output.
  3.    Tasks can connect to other tasks or to Milestones.  When
  4.    a path must split or join, a Milestone is required.  
  5.  
  6.    Tasks descend from Activity and inherit all of
  7.    their methods and instance variables.
  8. */!!
  9.  
  10. inherit(Activity, #Task, #(resources   /* a collection */
  11. time        /* required by task */
  12. cost        /* total task cost */
  13. fixedCost 
  14. ), 2, nil)!!
  15.  
  16. now(TaskClass)!!
  17.  
  18. now(Task)!!
  19.  
  20. /* Return the class name.  Uses resources for translation. */
  21. Def className(self)
  22. {
  23.   ^loadString(PW_TASK);
  24. }!!
  25.  
  26.  
  27. /* Return true if the task is "complete", e.g.
  28.    connected, time set etc.  
  29.    This is for experimental use only.   */
  30. Def  complete(self)
  31.   ^complete(self:Activity)
  32.      cand time <> 0
  33.      cand size(resources) > 0;
  34. }!!
  35.  
  36. /* Draw a Task at a location in a window.
  37.    The window manages the details of what the
  38.    Task will look like, since it could be
  39.    a PERT chart or a Gantt chart.    */
  40. Def  draw(self, window, x, y, hDC)
  41.   drawTask(window, self, x, y, hDC);
  42. }!!
  43.  
  44. /* Tasks can have only a single connection at
  45.    inputs and outputs.  If you attempt to connect
  46.    multiple inputs or outputs, an error message
  47.    will be displayed.  */
  48. Def  maxConnectionNames(self, names | connected)
  49. {   
  50.   if size(names) > 1
  51.     beep();
  52.     errorBox(loadString(PW_ERRCONNECT1),
  53.       loadString(PW_ERRCONNECT2) + CR_LF +
  54.       loadString(PW_ERRCONNECT3));
  55.     names := copyFrom(names, 0, 1);
  56.   endif;
  57.   ^names;
  58. }!!
  59.  
  60. /* Check to see if the resources have changed.
  61.    If so, remove the old ones add the new ones. */
  62. Def  checkResources(self, newResNames | oldResNames, res)
  63. {
  64.   oldResNames := getResourceNames(self);
  65.   
  66.   if newResNames <> oldResNames       /* resources changed */
  67.     do(resources,
  68.       {using(oldRes) 
  69.        removeResource(self, oldRes);
  70.      });
  71.     res := parseResNames(network, newResNames);
  72.     
  73.     do(res,
  74.       {using(newRes)
  75.        addResource(self, newRes);       
  76.     });    
  77.     calcCost(self);   /* update cost */
  78.   endif;  
  79. }!!
  80.  
  81. /* Return a string of resource names. */
  82. Def  getResourceNames(self | str)
  83. {
  84.   str := "";
  85.   do(resources,
  86.     {using(res) str := str + getName(res) + " ";
  87.   });
  88.   ^str;  
  89. }!!
  90.  
  91. /* Return the appropriate dialog class to be used
  92.    by editInfo(). */
  93. Def  dialogClass(self)
  94. {
  95.   ^TaskDialog;
  96. }!!
  97.  
  98. /* Set the values of an activity. 
  99.    Values is an array of name, desc,
  100.    userEarlyStart, userLateFinish, time, 
  101.    fixedCost, resources. */
  102. Def  setValues(self, values | oldUES, oldULF, oldTime)
  103. {
  104.   oldUES := userEarlyStart;
  105.   oldULF := userLateFinish;
  106.   oldTime := time;
  107.   
  108.   name := values[0];
  109.   desc := values[1];
  110.   userEarlyStart := values[2];
  111.   userLateFinish := values[3];
  112.   time := values[4];
  113.   
  114.   setFixedCost(self, values[5]);
  115.   checkResources(self, values[6]);
  116.  
  117.   if network cand autoCalc(network) cand 
  118.      (oldUES <> userEarlyStart cor
  119.       oldULF <> userLateFinish cor
  120.       oldTime <> time)
  121.     recalc(self);
  122.   endif;
  123. }!!
  124.  
  125. /* Get the fixed cost. */
  126. Def  getFixedCost(self)
  127. { ^fixedCost;
  128. }!!
  129.  
  130. /* Get the cost. */
  131. Def  getCost(self)
  132. { ^cost;
  133. }!!
  134.  
  135. /* Calculate the cost of a Task and update the project cost. */
  136. Def  calcCost(self | oldCost)
  137.   oldCost := cost;
  138.   cost := fixedCost;
  139.   do(resources,
  140.     {using(elem)
  141.     cost := cost + getFixedCost(elem)
  142.                  + getTime(self) * getVariableCost(elem);
  143.   });
  144.   updateCost(network, cost - oldCost);
  145.   ^cost;
  146. }!!
  147.  
  148. /* Update the cost based on a change to a resource.
  149.    Pass the change in cost to the network also. */
  150. Def  updateCost(self, change)
  151.   cost := cost + change;
  152.   updateCost(network, change);
  153. }!!
  154.  
  155. /* Remove the resource for a task.  Also remove
  156.    the resource's reference to the task.  
  157.    Recalculate the cost if necessary. */
  158. Def  removeResource(self, res)
  159.   remove(resources, res);
  160.   removeReference(res, self);
  161.   if (getVariableCost(res) <> 0 
  162.       cor getFixedCost(res) <> 0)
  163.     calcCost(self);
  164.   endif;
  165. }!!
  166.  
  167. /* Add to the resources for a task creating the resource is
  168.    necessary.  The resource should also know where it is
  169.    referenced, in case it changes. Update cost if necessary. */
  170. Def  addResource(self, res)
  171.   add(resources, res);
  172.   addReference(res,self);     
  173.   if (getVariableCost(res) <> 0)
  174.     calcCost(self);
  175.   endif;
  176. }!!
  177.  
  178. /* Set the fixed cost for a task. */
  179. Def  setFixedCost(self, aCost | change)
  180.   change := aCost - fixedCost;
  181.   if (change <> 0)
  182.     fixedCost := aCost;
  183.     cost := cost + change;
  184.     updateCost(network, change);
  185.   endif;
  186. }!!
  187.  
  188. /* Initialize a new Task. */
  189. Def  init(self)
  190. {
  191.   init(self:Activity);      /* use ancestor init */
  192.   resources := new(Set, 5);
  193.   time := slack := cost := fixedCost := 0;
  194. } !!
  195.  
  196. /* Get the time. */
  197. Def  getTime(self)
  198. { ^time;
  199. }!!
  200.  
  201.  
  202.